#
import logging

from requests import Response
logger=logging.getLogger(__name__)

def equals_assert(actual,extrac_scope,data:object,expected, msg=None):
    print("调用相等断言")
    logger.info("调用相等断言")
    if "." not in extrac_scope:
        actual_code=getattr(data,actual)
        print("实际响应状态码为：",actual_code)
        print("预期响应状态码为：",expected)
        print("断言信息为：",msg)
        assert actual_code==expected, msg
        logger.info(f"{msg}断言成功")
def not_equals_assert(actual,extrac_scope,data:object,expected, msg=None):
    print("调用不相等断言")
    logger.info("调用不相等断言")
    if "." in extrac_scope:
        obj,func=extrac_scope.split(".")

        actual_data=getattr(data,func)()
        print("实际响应结果为：", actual_data[actual])
        print("预期响应结果为：", expected)
        print("断言信息为：", msg)
        print(f"<<<<<<<<<<<<<<<<<<{expected}")
        assert actual_data[actual]!=expected, msg
        logger.info(f"{msg}断言成功")
    # elif isinstance(Response,data):
    #     actual_code=getattr(data,actual)
    # assert
def include_assert(actual,extrac_scope,data, second_filed=None,index=None,msg=None):
    print("调用包含断言方法")
    logger.info("调用包含断言方法")
    if "." in extrac_scope:
        obj,func=extrac_scope.split(".")
        actual_data=getattr(data,func)()
        print(f"断言信息为：{msg},{actual}包含在了{actual_data}")
        print(f"响应体中{second_filed}字段值中是否包含了{actual}")
        if second_filed:
            actual_data=actual_data[second_filed]
            if index!=None:
                actual_data=actual_data[index]
        print(f"响应体中{actual_data}，是否包含了{actual}")
        assert actual in actual_data,msg
        logger.info(f"{msg}断言成功")
def not_include_assert(actual,extrac_scope,data:str, msg=None):
    if "." in extrac_scope:
        obj,func=extrac_scope.split(".")
        actual_data=getattr(data,func)()
        assert actual not in actual_data,msg
